import datetime

import boto3
from athena_submit import submit

s3 = boto3.client('athena', region_name="cn-northwest-1", aws_access_key_id="AKIAWTBG3E42IMYODWHL",
                  aws_secret_access_key="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")

def run():
    tables = ['fridge_kyd_sensor_fault_0512',
              'iot_fault_code_apprea_in_kyd ',
              'iot_fault_code_in_kyd ',
              'iot_fault_code_in_kyd_14days ',
              'iot_fault_code_in_kyd_20230505 ',
              'iot_fault_reported_during_kyddate ',
              'iot_fault_sensor_20220401_20230431 ',
              'iot_fault_sensor_sn ',
              'iot_fridge_fault_202204_202304 ',
              'iot_fridge_sn_test ',
              'iot_kyd_all_fault ',
              'iot_kyd_join_date_faults ',
              'iot_kyd_join_sns ',
              'iot_kyd_match_error_1m ',
              'iot_kyd_special_fault ']
    # tables = [
    #           'iot_kyd_city_compare ']

    for table in tables:
        table = table.replace(' ','')
        sql1 = f''' create table  test.{table}_b as select * from test.{table} '''
        submit(sql1)
        sql2 = f'drop table test.{table}'
        submit(sql2)
        sql3 = f'''
                create table  test.{table} WITH (
                      external_location = 's3://athena-testdata/{table}',
                      format = 'PARQUET')
                as select * from 
                test.{table}_b;
               '''
        submit(sql3)
        sql4 = f"drop table test.{table}_b"
        submit(sql4)
        print("done:",table)

if __name__ == '__main__':
    run()


